home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / UTILREEN / EGA2RAM.LZH / EGA2RAM.ASM next >
Assembly Source File  |  1988-03-13  |  12KB  |  317 lines

  1. ;                   EGA²RAM
  2. ;
  3. ;     EGA²RAM is a (memory-resident) device driver which copies IBM's EGA
  4. ;     BIOS code to RAM.  Since the IBM EGA is an 8-bit card, copying the
  5. ;     code to 16-bit RAM results in a significant improvement in graphics
  6. ;     performance.  This operation will NOT, of course, affect programs
  7. ;     which write directly to display memory; and note that the display
  8. ;     memory itself is not moved, only the BIOS code.
  9. ;
  10. ;     EXE2BIN must be run on EGA²RAM.EXE to convert it to .SYS format.
  11. ;     Then put a line in your CONFIG.SYS like "DEVICE = EGA2RAM.SYS" .
  12. ;
  13. ;
  14. ;             THIS PROGRAM WAS WRITTEN BY
  15. ;                 GREG ROELOFS
  16. ;                UNIVERSITY OF CHICAGO
  17. ;                11 MARCH 1988
  18. ;
  19. ;
  20. ;     Most recent revisions:  13 March 1988
  21. ;
  22. ;
  23.  
  24. CSEG        Segment
  25.         Assume    CS:CSEG, DS:NOTHING, ES:NOTHING
  26.  
  27.         Org    0000h            ; .SYS files start here
  28.  
  29. ;    Device header
  30. ;    -------------
  31.  
  32. HeaderPtr    dw    0FFFFh, 0FFFFh        ; pointer to next device driver
  33. Attrib        dw    8000h            ; character device, not block
  34. StrategyPtr    dw    Offset Strategy     ; routine to store request hdr
  35. InterruptPtr    dw    Offset Interrupt    ; routine to process request
  36. DriverName    db    "EGA²RAM$"              ; name of this driver
  37.  
  38. ;    Strategy routine
  39. ;    ----------------
  40.  
  41. Strategy:    MOV    CS:RequestOffset, BX    ; store offset and segment of
  42.         MOV    CS:RequestSegment, ES    ;  request header...
  43.         RETF                ; ...then return to DOS
  44.  
  45. RequestAddr    Label    DWord            ;
  46. RequestOffset    dw    0000            ; request header stuff goes here
  47. RequestSegment    dw    0000            ;
  48.  
  49. ;    Interrupt routine
  50. ;    -----------------
  51.  
  52. Interrupt:    PUSH    AX            ;
  53.         PUSH    BX            ;
  54.         PUSH    CX            ;
  55.         PUSH    DX            ;
  56.         PUSH    DS            ; save registers and flags
  57.         PUSH    ES            ;
  58.         PUSH    DI            ;
  59.         PUSH    SI            ;
  60.         PUSHF                ;
  61.  
  62.         LDS    BX, DWord Ptr RequestAddr    ; set DS:BX to req. hdr.
  63.         MOV    AL, [BX + 2]        ; get command code from header
  64.         OR    AL, AL            ; set flags
  65.         JNZ    NotINIT         ; if not zero (INIT), exit
  66.         JMP    Initialize        ; if zero, go do our thing
  67.  
  68. NotINIT:    MOV    AH, 1            ; 'done' bit in return status
  69.         MOV    [BX + 3], AX        ; send return status back
  70.         POPF                ;
  71.         POP    SI            ;
  72.         POP    DI            ;
  73.         POP    ES            ;
  74.         POP    DS            ; restore registers and flags
  75.         POP    DX            ;
  76.         POP    CX            ;
  77.         POP    BX            ;
  78.         POP    AX            ;
  79.         RETF                ; ... and leave
  80.  
  81. ;    EGA shadow BIOS goes here
  82. ;    -------------------------
  83.  
  84.         db    "EGA²RAM:  Copyright (c) 1988 by Greg Roelofs"
  85.  
  86. EGABIOS     Label    Byte
  87.         db    055h, 0AAh, 020h, 0EBh, 028h
  88.         db    '2400'
  89.         db    '6277356 (C)COPYRIGHT IBM 1984'
  90.         db    '9/13/84'
  91.         db    3942h dup (0)        ; total length = 3960h + 0Fh
  92.                         ;  bytes so we can align on
  93.                         ;  a segment boundary
  94.  
  95. ;    Throw-away data
  96. ;    ---------------
  97.  
  98. IntrptTable    Label    Word            ; offsets in low memory for
  99.         dw    10h*4            ;  INT 10h,
  100.         dw    1Fh*4            ;  INT 1Fh, and
  101.         dw    43h*4            ;  INT 43h
  102.  
  103. ErrorFlag    db    00            ; gets set to FFh if can't load
  104. ErrorHeader    dw    810Ch            ; indicates Gen. Failure to INIT
  105. SuccessHeader    dw    0100h            ; indicates INIT was successful
  106.  
  107. EndCodeAddr    Label    DWord            ;
  108. EndOffset    dw    Offset IntrptTable    ; if success, end of BIOS area
  109.  
  110. ;    Initialization code:  print message, load BIOS, revector vectors
  111. ;    ----------------------------------------------------------------
  112.  
  113. Initialize:    MOV    AH, 3            ; BIOS function to read cursor
  114.         XOR    BH, BH            ;  position (page 0) - using
  115.         INT    10h            ;  original EGA ROM BIOS
  116.         PUSH    DX            ; save current position on stack
  117.         MOV    AH, 8            ; BIOS function to read char/
  118.         INT    10h            ;  attribute at current position
  119.         PUSH    AX            ; will save current screen color
  120.  
  121.         PUSH    CS            ; load ES with segment
  122.         POP    ES            ;  we're in
  123.         MOV    BP, Offset InitMsg    ; address of string
  124.         MOV    DX, 011Dh        ; (row,col) to print string
  125.         MOV    CX, 8            ; 8 lines to print
  126. TitleLoop:    PUSH    CX            ; save count
  127.         MOV    CX, 51            ; number of characters per line
  128.         XOR    BH, BH            ; page 0
  129.         MOV    AX, 1303h        ; write string with
  130.         INT    10h            ;  individual attributes
  131.         INC    DH            ; next row
  132.         ADD    BP, 2*51        ; next batch of characters
  133.         POP    CX            ; get count...
  134.         LOOP    TitleLoop        ; ...and go back for next line
  135.  
  136. ;    Compare first 2Dh bytes of EGA BIOS to make sure IBM's
  137. ;    ------------------------------------------------------
  138.  
  139.         CLD                ; forward direction for strings
  140.         MOV    DI, Offset EGABIOS    ; ES still points to the current
  141.         MOV    DX, 0C000h        ;  segment (from above)
  142.         MOV    DS, DX            ; point DS:SI to EGA ROM segment
  143.         XOR    SI, SI            ;  (C000:0000h)
  144.         MOV    CX, 2Dh         ; number of bytes to compare
  145.  
  146.         REPE    CMPSB            ; do the comparison
  147.         JCXZ    LoadBIOS        ; string compares OK:  IBM EGA
  148.  
  149.         MOV    ErrorFlag, 0FFh     ; set error flag
  150.         MOV    BX, Offset EGABIOS    ; truncate since aborting: put
  151.         MOV    Word Ptr EndCodeAddr, BX    ;  it in temporary variable
  152.         MOV    BP, Offset ErrorMsg    ; address of error message: not
  153.         JMP    SHORT FinalMessage    ;  an EGA BIOS ==> not installed
  154.  
  155. ;    EGA BIOS is correct version:  begin copy operation to segment boundary
  156. ;    ----------------------------------------------------------------------
  157.  
  158. LoadBIOS:    MOV    AX, Offset EGABIOS + 16 ; get offset into current
  159.         MOV    CL, 4            ;  segment, round up to nearest
  160.         SHR    AX, CL            ;  multiple of 16, and divide
  161.         MOV    BX, ES            ;  by 16 (shift right 4 bits)
  162.         ADD    AX, BX            ;  to get number of 16-byte
  163.         MOV    ES, AX            ;  paragraphs to add to ES; DS
  164.                         ;  is still okay
  165.         XOR    DI, DI            ; reset source and destination
  166.         XOR    SI, SI            ;  offsets to 0 (segment bdry)
  167.         MOV    CX, 1CB0h        ; number of WORDS to move
  168.         REP    MOVSW            ; do it
  169.  
  170. ;    Copy of BIOS now resides in RAM:  fix up vectors, etc.
  171. ;    ------------------------------------------------------
  172.  
  173.         XOR    DX, DX            ; clear DX
  174.         MOV    DS, DX            ; set DS to low memory
  175.         MOV    BX, DS:[04A8h]        ; get offset of SAVE_TBL
  176.         MOV    ES:[BX + 2], ES     ; replace C000h with new segment
  177.  
  178.         CLI                ; disable interrupts while busy
  179.         MOV    DS:[04AAh], ES        ; replace SAVE_TBL segment
  180.         MOV    CX, 3            ; need to change 3 interrupts
  181.         MOV    SI, Offset IntrptTable    ; location of table for INT vecs
  182.  
  183. FixInterrupts:    MOV    BX, CS:[SI]        ; DX = offset into low-mem table
  184.         MOV    [BX + 2], ES        ; re-vector segment only
  185.         ADD    SI, 2            ; ready for next interrupt
  186.         LOOP    FixInterrupts        ; do it
  187.  
  188.         STI                ; re-enable interrupts
  189.  
  190. ;    Print final message (note:  using shadow BIOS, if load was successful)
  191. ;    ----------------------------------------------------------------------
  192.  
  193.         MOV    BP, Offset FinalMsg    ; successful load
  194. FinalMessage:    PUSH    CS            ; reset ES to the current
  195.         POP    ES            ;  segment
  196.         MOV    DX, 071Fh        ; (row,col) to print string
  197.         MOV    CX, 42            ; number of characters in string
  198.         XOR    BH, BH            ; page 0
  199.         MOV    AX, 1303h        ; write string with
  200.         INT    10h            ;  individual attributes
  201.  
  202.         MOV    BP, Offset BlankLine    ; address of string
  203.         POP    BX            ; retrieve old attribute (BH)
  204.         XCHG    BH, BL            ; put it in BL
  205.         XOR    BH, BH            ; page 0
  206.         POP    DX            ; retrieve old cursor position
  207.         MOV    CX, 11            ; space, 9 LFs, CR
  208.         MOV    AX, 1301h        ; write string with
  209.         INT    10h            ;  group attribute, move cursor
  210.  
  211. ;    Set up exit code for INIT data area and return to DOS control
  212. ;    -------------------------------------------------------------
  213.  
  214.         MOV    AX, SuccessHeader    ; 'done' bit in return status
  215.         CMP    ErrorFlag, 0        ; was it really successful?
  216.         JE    ReturnInfo        ; yes
  217.         MOV    AX, ErrorHeader     ; no
  218.  
  219. ReturnInfo:    LDS    BX, DWord Ptr RequestAddr    ; set DS:BX to req. hdr.
  220.         MOV    [BX + 3], AX        ; send return status back
  221.         MOV    AX, EndOffset        ; get end-of-code offset...
  222.         MOV    [BX + 14], AX        ; ...and give to DOS...
  223.         MOV    [BX + 16], ES        ; ...as well as EOC segment
  224.         POPF                ;
  225.         POP    SI            ;
  226.         POP    DI            ;
  227.         POP    ES            ;
  228.         POP    DS            ; restore registers and flags
  229.         POP    DX            ;
  230.         POP    CX            ;
  231.         POP    BX            ;
  232.         POP    AX            ;
  233.         RETF                ; ... and leave
  234.  
  235. ;    More data (installation message)
  236. ;    --------------------------------
  237.  
  238. .RADIX 16
  239. InitMsg     db    "╔",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  240.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"╤",0E
  241.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  242.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  243.         db    "═",0E,"╤",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  244.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  245.         db    "═",0E,"═",0E,"╗",0E
  246.         db    "║",0E," ",07,"V",0C,"e",0C,"r",0C,"s",0C,"i",0C,"o",0C
  247.         db    "n",0C," ",0C,"1",0C,".",0C,"0",0C,"0",0C," ",0E,"│",0E
  248.         db   " ",0E," ",0E," ",0E," ",0E," ",0E,"E",0Dh,"G",0Dh,"A",0Dh
  249.         db    "²",0E,"R",09,"A",09,"M",09," ",0E," ",0E," ",0E," ",0E
  250.         db    " ",0E,"│",0E," ",0E," ",0C,"1",0C,"3",0C," ",0C,"M",0C
  251.         db    "a",0C,"r",0C,"c",0C,"h",0C," ",0C,"1",0C,"9",0C,"8",0C
  252.         db    "8",0C," ",07,"║",0E
  253.         db    "╟",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  254.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"┴",0E
  255.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  256.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  257.         db    "─",0E,"┴",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  258.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  259.         db    "─",0E,"─",0E,"╢",0E
  260.         db    "║",0E," ",07,"A",02,"n",02,"o",02,"t",02,"h",02,"e",02
  261.         db    "r",02," ",02,"n",02,"i",02,"f",02,"t",02,"y",02," ",02
  262.         db    "p",02,"r",02,"o",02,"d",02,"u",02,"c",02,"t",02," ",02
  263.         db    "f",02,"r",02,"o",02,"m",02," ",02,"t",02,"h",02,"e",02
  264.         db    " ",02,"f",02,"o",02,"l",02,"k",02,"s",02," ",02,"a",02
  265.         db    "t",02," ",02,"A",0A,"w",0A,"e",0A,"s",0A,"o",0A,"m",0A
  266.         db    "e",0A," ",07,"║",0E
  267.         db    "║",0E," ",07,"C",0A,"o",0A,"m",0A,"p",0A,"u",0A,"t",0A
  268.         db    "i",0A,"n",0A,"g",0A," ",0A,"C",0A,"o",0A,"m",0A,"p",0A
  269.         db    "a",0A,"n",0A,"y",0A,",",02," ",02,"a",02," ",02,"d",02
  270.         db    "i",02,"v",02,"i",02,"s",02,"i",02,"o",02,"n",02," ",02
  271.         db    "o",02,"f",02," ",02,"D",0A,"E",0A," ",0A,"E",0A,"n",0A
  272.         db    "t",0A,"e",0A,"r",0A,"p",0A,"r",0A,"i",0A,"s",0A,"e",0A
  273.         db    "s",0A," ",07,"║",0E
  274.         db    "╟",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  275.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  276.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  277.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  278.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  279.         db    "─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E,"─",0E
  280.         db    "─",0E,"─",0E,"╢",0E
  281.         db    "║",0E," ",07,"C",03,"o",03,"p",03,"y",03,"i",03,"n",03
  282.         db    "g",03," ",03,"1",03,"4",03,",",03,"6",03,"8",03,"8",03
  283.         db    " ",03,"b",03,"y",03,"t",03,"e",03,"s",03," ",03,"o",03
  284.         db    "f",03," ",03,"E",03,"G",03,"A",03," ",03,"B",03,"I",03
  285.         db    "O",03,"S",03," ",03,"t",03,"o",03," ",03,"R",03,"A",03
  286.         db    "M",03,".",03,".",03,".",03," ",03," ",03," ",03," ",03
  287.         db    " ",03," ",07,"║",0E
  288.         db    "╚",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  289.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  290.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  291.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  292.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  293.         db    "═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E,"═",0E
  294.         db    "═",0E,"═",0E,"╝",0E
  295.  
  296.  
  297. ErrorMsg    db    "N",03,"o",03,"n",03,"-",03,"I",03,"B",03
  298.         db    "M",03," ",03,"E",03,"G",03,"A",03," ",03,"B",03,"I",03
  299.         db    "O",03,"S",03,":",03," ",03," ",03,"i",03,"n",03,"s",03
  300.         db    "t",03,"a",03,"l",03,"l",03,"a",03,"t",03,"i",03,"o",03
  301.         db    "n",03," ",03,"a",03,"b",03,"o",03,"r",03,"t",03,"e",03
  302.         db    "d",03,".",03," ",03," ",03
  303.  
  304. FinalMsg    db    "I",03,"n",03,"s",03,"t",03,"a",03,"l",03
  305.         db    "l",03,"a",03,"t",03,"i",03,"o",03,"n",03," ",03,"c",03
  306.         db    "o",03,"m",03,"p",03,"l",03,"e",03,"t",03,"e",03,",",03
  307.         db    " ",03,"y",03,"o",03,"u",03," ",03,"b",03,"e",03,"t",03
  308.         db    "c",03,"h",03,"a",03,".",03," ",03," ",03," ",03," ",03
  309.         db    " ",03," ",03," ",03," ",03
  310.  
  311. BlankLine    db    " ", 0A, 0A, 0A, 0A, 0A, 0A, 0A, 0A, 0A, 0Dh
  312.  
  313.  
  314. CSEG        ENDS                    ;
  315.  
  316.         END                    ; denotes entry point
  317.